package se.webbzon.boltzmann.game.object.trigger;

import java.nio.ByteBuffer;

import se.webbzon.oschi01.worldeditor.WorldObjectDeflation;
import se.webbzon.oschi01.worldobject.WorldObject;

public class AbstractTriggerDeflation extends WorldObjectDeflation {

	private TriggerCondition condition;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new empty abstract trigger deflation. **/
	public AbstractTriggerDeflation(int deflationProperties,
									WorldObject[] dependencies) {
		super(deflationProperties, dependencies);
	}
	
	/** Creates a new abstract trigger deflation from an
	 * existing trigger. **/
	public AbstractTriggerDeflation(int deflationProperties,
									WorldObject[] dependencies,
									AbstractTrigger trigger) {
		super(deflationProperties, dependencies);
		condition = trigger.getCondition();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the condition of this trigger deflation. **/
	public TriggerCondition getCondition() {
		return condition;
	}
	
	@Override public void inflate(ByteBuffer buff) {
		condition = TriggerCondition.values()[buff.getInt()];
	}

	@Override public ByteBuffer deflate(int allocate) {
		ByteBuffer buff = ByteBuffer.allocate(allocate + 4);
		buff.putInt(condition.ordinal());
		return buff;
	}
	
}
